package io.renren.modules.job.task;

import io.renren.common.constants.enums.PayState;
import io.renren.common.constants.enums.PayType;
import io.renren.common.constants.enums.ResponseStatus;
import io.renren.common.rpc.ApiResult;
import io.renren.common.rpc.OutrestSimidaFeignRpc;
import io.renren.modules.simida.entity.UserFundLogEntity;
import io.renren.modules.simida.service.UserFundLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: miaoguoxin
 * @Date: 2019/11/22 15:20
 * @Description: 对账定时任务
 */
@Component("reconciliationTask")
@Slf4j
public class ReconciliationTask implements ITask {
    @Autowired
    private UserFundLogService fundLogService;
    @Autowired
    private OutrestSimidaFeignRpc outrestSimidaFeignRpc;

    @Override
    public void run(String params) {
        log.info("开始执行对账任务");
        Map<String, Object> conditions = new HashMap<>();
        conditions.put("payState", PayState.PRE_SUCCESS.getValue());
        conditions.put("state", 1);
        List<UserFundLogEntity> userFundLogEntityList = fundLogService.queryByCondition(conditions);
        for (UserFundLogEntity userFundLogEntity : userFundLogEntityList) {
            ApiResult<Boolean> apiResult = outrestSimidaFeignRpc.compensatePay(userFundLogEntity.getTradeNumber());
        }
        log.info("结束执行对账任务");
    }
}
